<?php

namespace app\admin\controller;

use think\Controller;
use think\Session;

class User extends Controller
{
    protected $db;
    public function __construct()
    {
        parent::__construct();
        $this->db = new \app\common\model\User();
    }

    //登录
    public function login(){
        if(request()->isPost()){
            $res = $this->db->login(input('post.'));
            if($res['valid']){
                $this->success($res['msg'],'admin/index/index');
            }else{
                $this->error($res['msg']);
            }
        }
        //1.载入视图
        return view();
    }
    //修改密码
    public function editPsw(){
        if(request()->isPost()){
            $res = $this->db->editPsw(input('post.'));
            if($res['valid']){
                $this->success('更新成功，即将跳转到登录页面','admin/index/index');
            }else{
                $this->error($res['msg']);
            }
        }
        return view();
    }

    //退出
    public function out(){
        Session::delete('admin');
        $this->redirect('admin/user/login');
    }
}
